#!/usr/bin/perl
print "Content-type: text/html; charset=utf-8\n\n";

sub mp3_tag_read
{
	# use module
	use MP3::Tag;

	# set filename of MP3 track
	$filename = shift;

	# create new MP3-Tag object
	$mp3 = MP3::Tag->new($filename);
	$mp3->get_tags();

	# if ID3v2 tags exists
	if (exists $mp3->{ID3v2})
	{
		# get a list of frames as a hash reference
		$frames = $mp3->{ID3v2}->get_frame_ids();

		# iterate over the hash
		# process each frame
		foreach $frame (keys %$frames) 
		{
			# for each frame
			# get a key-value pair of content-description
			($value, $desc) = $mp3->{ID3v2}->get_frame($frame);
		
			#print "$frame $desc: ";
		
		
			# sometimes the value is itself a hash reference containing more values
			# deal with that here
			if (ref $value)
			{
				while (($k, $v) = each (%$value))
				{
					print "\n     - $k: $v";
				}
				print "\n";
			}
			else
			{
				#print "$value\n";
				print $frame."\t".$value."</br>";
				#$hash{$frame} = $value;
			}
		#print $frame.$value;
		}
	}
	$mp3->close();
	return %hash;
}
sub write_tag
{
	use MP3::Tag;
	$filename = shift;
	
	$mp3 = MP3::Tag->new($filename);
	$id3v2 = $mp3->new_tag("ID3v2");
	
	$id3v2->remove_frame("TIT2");
	$id3v2->add_frame("TIT2", "Title of the song");
	$id3v2->write_tag();
}


%fff = mp3_tag_read("14.mp3");
print $fff{"TIT2"}
